﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Chevron.OrderDetails.Models
{
    public class TestCatalog : Dictionary<string, LabTestDto>
    {
        public void LoadCatalogFromFile(string fname, TestCategoryCatalog catalog)
        {
            using (var sr = new StreamReader(fname, Encoding.Default))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    string alaLineCode = Utilities.ExtractAlaCode(line);

                    if (!string.IsNullOrEmpty(alaLineCode) && (string.Compare(alaLineCode, "OC", true) == 0))
                    {
                        try
                        {
                            LabTestDto test = LabTestDto.Deserialize(line, catalog);
                            Add(test.TestCode, test);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
        }
    }
}